package com.rem.zookeeper.lock;

public class DistributedLockTest {
    public static void main(String[] args) {
        for (int i = 1; i <= 2; i++) {
            int finalI = i;
            new Thread(() -> {
                // 获取锁对象
                try {
                    DistributedLock distributedLock = new DistributedLock();
                    distributedLock.zkLock();
                    System.out.println("线程 " + finalI + " 获取锁");
                    Thread.sleep(finalI * 1000);
                    distributedLock.zkUnlock();
                    System.out.println("线程 " + finalI + " 释放锁");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }).start();
        }
    }
}
